package com.todo.biz.application.frontend.controller;

import com.todo.common.common.entity.response.BizPageResponse;
import com.todo.common.common.entity.response.BizResponse;
import com.todo.biz.application.frontend.service.CommentAggService;
import com.todo.biz.iface.frontend.CommentFrontendIface;
import com.todo.biz.iface.frontend.request.InsertCommendParam;
import com.todo.biz.iface.frontend.request.QueryCommentByParentIdParam;
import com.todo.biz.iface.frontend.request.RemoveCommentByIdParam;
import com.todo.biz.iface.frontend.response.CommentVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author azhebuxing
 * @date 2024/5/28 14:37
 * @description
 */
@Slf4j
@RestController
@RequestMapping("/bizBase/comment")
@Tag(name = "评论前台接口", description = "评论前台接口")
public class CommentFrontendController implements CommentFrontendIface {

    @Resource
    private CommentAggService commentAggService;


    @Override
    @Operation(summary = "新增评论")
    @PostMapping("/insertComment")
    public BizResponse<Boolean> insertComment(@RequestBody InsertCommendParam param) {
        if (param == null) {
            return BizResponse.success("查询异常，请刷新后重新操作");
        }
        if (!param.baseCheck()) {
            return BizResponse.success("查询失败，请刷新后重新操作");
        }
        return commentAggService.insertComment(param);
    }

    @Override
    @Operation(summary = "根据主键删除评论")
    @PostMapping("/removeCommentById")
    public BizResponse<Boolean> removeCommentById(@RequestBody RemoveCommentByIdParam param) {
        if (param == null) {
            return BizResponse.success("查询异常，请刷新后重新操作");
        }
        if (!param.baseCheck()) {
            return BizResponse.success("查询失败，请刷新后重新操作");
        }
        return commentAggService.removeCommentById(param);
    }

    @Override
    @Operation(summary = "根据父Id查询评论列表")
    @PostMapping("/queryCommentByParentId")
    public BizPageResponse<CommentVO> queryCommentByParentId(@RequestBody QueryCommentByParentIdParam param) {
        if (param == null) {
            return BizPageResponse.success("查询异常，请刷新后重新操作");
        }
        if (!param.baseCheck()) {
            return BizPageResponse.success("查询失败，请刷新后重新操作");
        }
        return commentAggService.queryCommentByParentId(param);
    }
}
